package com.team.teamproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.squareup.picasso.Picasso;
import com.team.teamproject.R;
import com.team.teamproject.bean.Category_Channels;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by Administrator on 2016/11/7.
 */

public class MyGridViewAdapter extends BaseAdapter {
    private List<Category_Channels.ChannelsBean> channelsBeen;
    private Context context;
    private int count;
    public MyGridViewAdapter(List<Category_Channels.ChannelsBean> channelsBeen, Context context,int count) {
        this.channelsBeen = channelsBeen;
        this.context = context;
        this.count=count;
    }

    @Override
    public int getCount() {
        return count;
    }

    @Override
    public Object getItem(int position) {
        return channelsBeen.get(position);
    }


    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = LayoutInflater.from(context);
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.fragment_category_item, null);
            holder = new ViewHolder(convertView);
            holder.strategyImage = (ImageView) convertView.findViewById(R.id.strategy_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        Category_Channels.ChannelsBean channels = channelsBeen.get(position);
        Picasso.with(context).load(channels.getCover_image_url()).into(holder.strategyImage);
        return convertView;
    }

    static class ViewHolder {
        @InjectView(R.id.strategy_image)
        ImageView strategyImage;

        ViewHolder(View view) {
            ButterKnife.inject(this, view);
        }
    }
}
